package com.test.account.controller;

import com.test.account.entity.Account;
import com.test.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/account")
public class AccountController {

    private final AccountService accountService;

    @Autowired
    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    @PostMapping
    public void create(Account account) {
        accountService.save(account);
    }

    @PutMapping("/debit/{userId}/{money}")
    public void debit(@PathVariable("userId") String userId,
                      @PathVariable("money") Integer money) {
        accountService.debit(userId, money);
    }

}
